<template>
  <a-card :bordered="false">
    <div class="title_blue">账套管理</div>
    <div class="title_black">奖励记录</div>
    <div class="divider_line"></div>
    <div>
      <a-table ref="table" size="middle" :scroll="{ x: false, y: false }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="false"  :loading="loading" class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="footer">
          <div style="display: flex; align-items: center; justify-content: space-between;">
            <div style="margin-left: 0.5rem;">合计</div>
            <div style="margin-right: 0.6rem;">{{footerDataSource.userNumber}}</div>
          </div>
        </template>
        <template slot="goodsNumber" slot-scope="text, record">
          <div v-if="record.goodsType == 1">{{ text }}年</div>
          <div v-else-if="record.goodsType == 2">{{ text }}用户</div>
          <div v-else-if="record.goodsType == 3">{{ text }}单</div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="noteSlot" slot-scope="text, record">
          <j-ellipsis :value="text" :length="15" />
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { getAction } from '../../../api/manage'

export default {
  name: 'RewardRecords',
  mixins: [JeecgListMixin, mixinDevice],
  components: {

  },
  data() {
    return {
      description: '授权中心订单管理页面',
      // 表头
      columns: [
        {
          title: '用户名称',
          align: "center",
          width: 50,
          dataIndex: 'username'
        },
        {
          title: '用户手机号',
          align: "center",
          width: 100,
          dataIndex: 'phone'
        },
        {
          title: '邀请类型',
          align: "center",
          width: 70,
          dataIndex: 'typeText'
        },
        {
          title: '注册时间',
          align: "center",
          width: 130,
          dataIndex: 'registerTime',
        },
        {
          title: '购买时间',
          align: "center",
          width: 130,
          dataIndex: 'createTime1'
        },
        // {
        //   title: '邀请人',
        //   align: "center",
        //   width: 100,
        //   dataIndex: 'postName'
        // },
        // {
        //   title: '邀请人手机号',
        //   align: "center",
        //   width: 100,
        //   dataIndex: 'postPhone'
        // },
        // {
        //   title: '邀请时间',
        //   align: "center",
        //   width: 130,
        //   dataIndex: 'payTime',
        // },
        {
          title: '奖励天数',
          align: "center",
          width: 60,
          dataIndex: 'rewardDays'
        },
      ],
      footerDataSource: [{
        createTime: '合计',
        userNumber: 0,
      }],
      // url: {
      //   list: "/xghrewardrecord/xghRewardRecord/list",
      // },
      dictOptions: {},
      superFieldList: [],
      xghAccountBookId: this.$route.query.id
    }
  },
  created() {
    this.getSuperFieldList();
    this.getData()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    getData () {
      let url = "/xghrewardrecord/xghRewardRecord/list"
      getAction(url, {
        xghAccountBookId: this.xghAccountBookId
      }).then(res => {
        console.log(res);
        if (res.code = 200) {
          let list = res.result || []
						let count = 0
						for (var i = 0; i < list.length; i++) {
							let item = list[i]
							if (item.inviteType == 1) {
                item.typeText = '注册'
                item.createTime1 = ''
							} else if (item.inviteType == 2) {
                item.typeText = '购买'
                item.createTime1 = item.createTime
                item.createTime = ''
							}
							count += item.rewardDays
						}
						this.footerDataSource.userNumber = count
          this.dataSource = list
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleFooterShow(data) {
      return (
        <a-table
          rowKey={Math.random}
          bordered={false}
          pagination={false}
          columns={this.columns}
          dataSource={this.footerDataSource}
          showHeader={false}
          size="small"
        ></a-table>
      );
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'orderNumber', text: '订单编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'userId', text: '用户id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'payType', text: '支付方式：1.微信 2.支付宝', dictCode: 'authorization_center_pay_type' })
      fieldList.push({ type: 'int', value: 'orderStatus', text: '订单状态：1.待付款 2.支付中，3.已完成 4.支付失败', dictCode: 'authorization_center_order_status' })
      fieldList.push({ type: 'datetime', value: 'payTime', text: '支付时间' })
      fieldList.push({ type: 'BigDecimal', value: 'orderMoney', text: '应收金额', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'payMoney', text: '实收金额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'goodsName', text: '商品名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'goodsId', text: '商品id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'goodsType', text: '商品类型：1.账套（版本） 2.用户数 3.云备份数', dictCode: 'authorization_center_goods_type' })
      fieldList.push({ type: 'int', value: 'goodsNumber', text: '商品数量（账套默认年，用户数默认无单位，云备份单位个）', dictCode: '' })
      fieldList.push({ type: 'int', value: 'paySecret', text: '支付密钥（用于银盛支付回调验证）', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';


.title_blue {
  font-size: 16px;
  font-family: PingFang SC-Semibold, PingFang SC;
  font-weight: 600;
  color: #1B94FB;
}

.title_black {
  font-size: 17px;
  font-family: PingFang SC-Medium, PingFang SC;
  font-weight: 500;
  color: #000000;
  margin-top: 30px;
}

.divider_line {
  background-color: #1B94FB;
  width: 100%;
  height: 2px;
  margin: 15px 0;
}

:v-deep .ant-table-footer {
  padding: 16px 8px;
}
</style>